package ch02.demo;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class demo1 {
    public static void main(String[] args) {
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse("src/ch02/demo/demo.xml");
            NodeList list = doc.getElementsByTagName("Brand");
            for (int i=0;i<list.getLength();i++){
                Node brand=list.item(i);
                Element element=(Element) brand;
                String attrValue=element.getAttribute("name");
                NodeList types=element.getChildNodes();
                for (int j=0;j<types.getLength();j++){
                    Element typeElement=((Element) types.item(j));
                    String type=typeElement.getAttribute("name");
                    System.out.println("手机"+type);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * ssssssssssssssssadadasdwdawsdawdsdawdsawdwadsdadsdwadadaaddwsdawdawdasdwsdwadawddadadadcdczzczzczcczcssdd
     */
}
